package com.hspedu.static_;

/**
 * @Author Stringzhua
 * @Date 2024/3/4 18:54
 * description:
 * 问题分析:
 * 1.count是一个独立于对象很尴尬
 * 2.以后访问count很麻烦,没有用到OOP
 * 3.因此,我们引出 类变量/静态变量
 */
public class ChildGame {
    public static void main(String[] args) {
        //定义变量count统计有多少小孩加入了游戏
        int count = 0;

        Child child01 = new Child("白骨精");
        child01.join();
        count++;
        Child child02 = new Child("狐狸精");
        child02.join();
        count++;
        Child child03 = new Child("老鼠精");
        child03.join();
        count++;

        //游戏结束
        System.out.println("共有count = " + count + "个小孩加入了游戏~");
    }
}

class Child {
    private String name;

    public Child(String name) {
        this.name = name;
    }

    public void join() {
        System.out.println(name + " 加入了游戏");
    }
}
